var $table = $("#table");
$(function () {
    var options = {
        url: contextPath + 'permission/list', //请求url
        idField: 'id', //主键
        parentIdField: 'parentId', // 父菜单字段名
        treeShowField: 'name', // 在哪一列展开树形
        columns: [
            {
                title: '序号', width: 20, formatter: function (value, row, index) {
                    return index + 1;
                }
            },
            {field: 'id', visible: false},
            {title: '名称', field: 'name', width: '200px'},
            {title: '地址', field: 'url', width: '300px'},
            {title: '权限值', field: 'code', width: '300px'},
            {title: '图标', field: 'icon', width: '100px', formatter: iconFormatter},
            {
                title: '类型', field: 'type', width: '100px', formatter: function (value, row, index) {
                    return value == 1 ? '菜单' : '按钮';
                }
            },
            {title: '操作', visible: false, field: 'action', width: '100px', formatter: $.operationFormatter},
        ]
    };

    // 调用common.js的treeTable()
    $.treeTable(options);
});

function iconFormatter(value, row, index) {
    return '<span class="' + value + '"></span>'
}